﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using welding.Model;

namespace welding
{
    /// <summary>
    /// 处理与设备相关的
    /// </summary>
   class DeviceController
    {
        private string cmdString;
        private DeviceResponseClass deviceResponse;

        private DeviceDataClass deviceData;
        public DeviceController(DeviceDataClass deviceData)
        {
            this.deviceData = deviceData;
        }

        public DeviceController(string cmdString)
        {
            this.CmdString = cmdString;
            this.DeviceResponse = JsonConvert.DeserializeObject<DeviceResponseClass>(cmdString);

        }

        public string DeviceCommand(int command,string reason)
        {
            DeviceDataClass deviceData = new DeviceDataClass();
            deviceData.cmd = cmdHeader;
            deviceData.cmdTime = DateTime.Now.ToString("HHmmss");
            deviceData.deviceId = this.DeviceData.deviceId;
            deviceData.userId = "";
            deviceData.deviceCommand = command;
            deviceData.commandTime = DateTime.Now.ToString();
            deviceData.reason = reason;

            return JsonConvert.SerializeObject(deviceData, Formatting.Indented);
        }

        private string cmdHeader = "DEVICE";

        internal DeviceDataClass DeviceData { get => deviceData; set => deviceData = value; }
        public string CmdString { get => cmdString; set => cmdString = value; }
        internal DeviceResponseClass DeviceResponse { get => deviceResponse; set => deviceResponse = value; }
    }
}
